﻿using System.Linq;

//returnValue[i] = (00000001 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 1] = (00000010 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 2] = (00000100 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 3] = (00001000 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 4] = (00010000 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 5] = (00100000 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 6] = (01000000 & item) == 1 ? RelayStatus.On : RelayStatus.Off;
//returnValue[i + 7] = (10000000 & item) == 1 ? RelayStatus.On : RelayStatus.Off;		

namespace Innovative.ProXr
{
	/// <summary>
	/// Represents a single one byte value that can be used for
	/// sending commands to the device or for receiving data
	/// from the device.
	/// </summary>
	public class RelayByte
	{
		private byte _value = 0;

		/// <summary>
		/// Creates a new instance of RelayByte with a 
		/// value of 0.
		/// </summary>
		public RelayByte()
		{
		}

		/// <summary>
		/// Creates a new instance of RelayByte with
		/// the specified value.
		/// </summary>
		/// <param name="value">The initial byte value to assign to this instance</param>
		public RelayByte(byte value)
		{
			this.Value = value;
		}

		/// <summary>
		/// The byte value of this command
		/// </summary>
		public byte Value
		{
			get
			{
				return _value;
			}
			set
			{
				_value = value;
			}
		}

		/// <summary>
		/// Creates a new instance of a RelayByte object
		/// from the given byte value.
		/// </summary>
		/// <param name="value">A byte value.</param>
		/// <returns>A new RelayByte instance.</returns>
		public static implicit operator RelayByte(byte value)
		{
			return new RelayByte(value);
		}

		/// <summary>
		/// Returns the byte value from an existing
		/// RelayByte object.
		/// </summary>
		/// <param name="value">An instance of a RelayByte object.</param>
		/// <returns>The byte value of the given RelayByte instance.</returns>
		public static implicit operator byte(RelayByte value)
		{
			return value.Value;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static implicit operator RelayByte(int value)
		{
			return new RelayByte((byte)value);
		}

		/// <summary>
		/// Serves as a hash function for a particular type.
		/// </summary>
		/// <returns>A hash code for the current RelayByte.</returns>
		public override int GetHashCode()
		{
			return this.Value.GetHashCode();
		}

		/// <summary>
		/// Returns a string that represents the current object.
		/// </summary>
		/// <returns>A string that represents the current object.</returns>
		public override string ToString()
		{
			return string.Format("byte[{0}]", this.Value);
		}

		public static class RelayCounts
		{
			public static RelayByte[] One = new RelayByte[] { 1 };
			public static RelayByte[] Two = new RelayByte[] { 2 };
			public static RelayByte[] Three = new RelayByte[] { 3 };
			public static RelayByte[] Four = new RelayByte[] { 4 };
			public static RelayByte[] Five = new RelayByte[] { 5 };
			public static RelayByte[] Size = new RelayByte[] { 6 };
			public static RelayByte[] Seven = new RelayByte[] { 7 };
		}
	}
}
